package com.atguigu.sparkcore.day02.kv

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

/**
 * Author atguigu
 * Date 2020/10/28 15:40
 */
object SortByKey {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
    
        //2.创建SparkContext，该对象是提交Spark App的入口
        val sc: SparkContext = new SparkContext(conf)
    
        //3具体业务逻辑
        //3.1 创建第一个RDD
        val rdd1 = sc.makeRDD(List(("ab", 1), ("aab", 5), ("bba", 2), ("aaaa", 7), ("bbba", 5), ("aaab", 2)), 2)
        
        val rdd2 = rdd1.sortBy(_._1.length)
        rdd2.collect().foreach(println)
        
    
    }
}
